package ie.timalb.chess.test.rules;

import ie.timalb.chess.main.core.Board;
import ie.timalb.chess.main.core.Player;
import ie.timalb.chess.main.core.Turn;
import ie.timalb.chess.main.core.movement.Movement;
import ie.timalb.chess.main.core.pieces.Pawn;
import ie.timalb.chess.main.core.pieces.Piece;
import ie.timalb.chess.main.core.pieces.Piece.Color;
import ie.timalb.chess.main.core.rules.RulesEngine;
import ie.timalb.chess.main.core.squares.Square;
import junit.framework.TestCase;

public class PawnTesterPopulatedBoard extends TestCase {
	public void testKoMovingBlackPawnToAPopulatedSquare () throws Exception
	{
		Square sourceLoc = new Square (4,5);
		Square finalLoc = new Square (4,4);
		Piece pieceToMove = new Pawn (Color.BLACK);
		RulesEngine rulesEng = new RulesEngine();
		Board board = new Board();
		board.addPiece ((Piece) new Pawn(Color.WHITE), new Square (4,4));
		boolean isValidated = false;
		
		Movement movToTest = new Movement (pieceToMove, sourceLoc, finalLoc);
		Turn turn = new Turn(new Player(Color.BLACK));
		isValidated = rulesEng.ValidateMovement(turn, movToTest, board);
		assertEquals(isValidated, false);
	}
	
	public void testKoMovingBlackPawnToAPopulatedSquare2 () throws Exception
	{
		Square sourceLoc = new Square (4,5);
		Square finalLoc = new Square (4,4);
		Piece pieceToMove = new Pawn (Color.BLACK);
		RulesEngine rulesEng = new RulesEngine();
		Board board = new Board();
		board.addPiece ((Piece) new Pawn(Color.WHITE), new Square (3,4));
		board.addPiece ((Piece) new Pawn(Color.WHITE), new Square (4,4));
		boolean isValidated = false;
		
		Movement movToTest = new Movement (pieceToMove, sourceLoc, finalLoc);
		Turn turn = new Turn(new Player(Color.BLACK));
		isValidated = rulesEng.ValidateMovement(turn, movToTest, board);
		assertEquals(isValidated, false);
	}
	
	public void testOkMovingWhitePawnSquareAhead1 () throws Exception
	{
		Square sourceLoc = new Square (2,2);
		Square finalLoc = new Square (2,3);
		Piece pieceToMove = new Pawn (Color.WHITE);
		RulesEngine rulesEng = new RulesEngine();
		Board board = new Board();
		board.addPiece ((Piece) new Pawn(Color.WHITE), new Square (3,4));
		boolean isValidated = false;
		
		Movement movToTest = new Movement (pieceToMove, sourceLoc, finalLoc);
		Turn turn = new Turn(new Player(Color.WHITE));
		isValidated = rulesEng.ValidateMovement(turn, movToTest, board);
		
		assertEquals(isValidated, true);
	}
	
	public void testKoMovingBlackPawnCrossingAPopulatedSquare2 () throws Exception
	{
		Square sourceLoc = new Square (3,7);
		Square finalLoc = new Square (3,5);
		Piece pieceToMove = new Pawn (Color.BLACK);		
		Board board = new Board();
		board.addPiece ((Piece) new Pawn(Color.WHITE), new Square (3,6));
		board.addPiece ((Piece) new Pawn(Color.WHITE), new Square (4,4));
		
		boolean isValidated = false;
		
		RulesEngine rulesEng = new RulesEngine();				
		Movement movToTest = new Movement (pieceToMove, sourceLoc, finalLoc);
		Turn turn = new Turn(new Player(Color.BLACK));
		isValidated = rulesEng.ValidateMovement(turn, movToTest, board);
		assertEquals(isValidated, false);
	}
	
	public void testOKMovingBlackPawnInDiagonalToKill () throws Exception
	{
		Square sourceLoc = new Square (3,7);
		Square finalLoc = new Square (4,6);
		Piece pieceToMove = new Pawn (Color.BLACK);		
		Board board = new Board();
		board.addPiece ((Piece) new Pawn(Color.WHITE), new Square (4,6));
		
		boolean isValidated = false;
		
		RulesEngine rulesEng = new RulesEngine();				
		Movement movToTest = new Movement (pieceToMove, sourceLoc, finalLoc);
		Turn turn = new Turn(new Player(Color.BLACK));
		isValidated = rulesEng.ValidateMovement(turn, movToTest, board);
		assertEquals(isValidated, true);
	}

}
